package finalproject.controller.commands;

import finalproject.model.player.Player;
import finalproject.model.player.PlayerModel;
import finalproject.view.StringManager;

/**
 * The fight command
 * @author Dahmoul Salah
 *
 */
public class FightCommand extends Command {

	/**
	 * 
	 * @param player the player issuing the command
	 * @param commandArgs the command args
	 */
	public FightCommand(Player player, String[] commandArgs)
	{
		super(player, commandArgs);
	}

	@Override
	public boolean process()
	{
		// 1st argument = player, 2nd = ability to use by pet
		if (getNbArguments() < 2)
		{
			
			StringManager.outPut("fightwhowhat");
			return false;
		}

		// Get the other player
		Player otherPlayer = PlayerModel.getInstance().getPlayer(getArgument(1));
		if (otherPlayer == null)
		{
			StringManager.outPut("playernotfound");
			return false;
		}

		// Not in same room
		if (!getPlayer().getCurrentRoom().equals(otherPlayer.getCurrentRoom()))
		{
			StringManager.outPut("notinsameroom");
			return false;
		}
		
		// Fight
		if (!getPlayer().getPet().useAbilities(getArgument(2), otherPlayer))
		{
			StringManager.outPut("abilitynameerror");
			return false;
		}
		
		return true;
	}
}
